package com.example.yiwei.crm.json;

import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by DHN on 2017/5/4.
 */

public class FindSpinnerJson {
    public static List<Map<String,String>> getSpinnerMessage(String result){
        List<Map<String, String>> list;
        list = new ArrayList<Map<String, String>>();
        try {
            JSONObject object = new JSONObject(result);
           boolean boolen = object.getBoolean("ifsuccess");
            if (boolen) {
                JSONArray array = object.getJSONArray("list");
                Object aobject = new Object();
                for (int i = 0; i < array.length(); i++) {
                    Map<String, String> map = new HashMap<String, String>();
                    JSONObject json = array.getJSONObject(i);
                    if (json.has("AKJ01")){
                        map.put("AKJ01",json.getString("AKJ01"));
                    }
                    if (json.has("AKJ03")){
                        map.put("AKJ03",json.getString("AKJ03"));
                    }
                    if (json.has("AKK03")){
                        map.put("AKK03",json.getString("AKK03"));
                    }
                    if (json.has("AKK01")){
                        map.put("AKK01",json.getString("AKK01"));
                    }
                    list.add(map);
                }
                return list;
            } else {
                Log.d("", "查询失败");
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return list;
    }
}
